# 用于保存发送短信的异步任务
import logging
from celery_tasks.main import app
from meiduo.libs.yuntongxun.sms import CCP

# logger = logging.getLogger('django')

# 验证短信模板
SMS_CODE_TEMP_ID = 1


@app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code):
    """
     发送短信验证码
    :param mobile:
    :param code:
    :param expires:
    :return:
    """
    # try:
    #      ccp = CCP()
    #      result = ccp.send_template_sms(mobile, [code, '5'], SMS_CODE_TEMP_ID)
    # except Exception as e:
    #      logger.error("发送短信验证码［异常］[mobile: %s, message: %s]" % (mobile, e))
    # else:
    #     if result == 0:
    #         logger.info("发送短信验证码［成功］[mobile: %s]" % mobile)
    #     else:
    #         logger.warning("发送短信验证码［失败］[mobile: %s]" % mobile)
    ccp=CCP()
    ccp.send_template_sms(mobile,[sms_code,'5'],1)
